package org.pp.controller;


import io.swagger.v3.oas.annotations.Operation;
import org.pp.admin.dto.PpOrderPage;
import org.pp.admin.dto.PpUserPage;
import org.pp.annotations.Permission;
import org.pp.core.PageBean;
import org.pp.core.Result;
import org.pp.entity.PpOrder;
import org.pp.store.OssStore;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
public class PpOrderController
        extends BaseCrudController<PpOrder,PpOrder,PpOrder,PpOrder>
implements BaseDetail<PpOrder>
{

    @Autowired
    OssStore ossStore;

    @GetMapping("/list")
    @Permission("get:/order/list")
    @Operation(summary = "分页查询")
    public Result<PageBean<PpOrder>> page(@ParameterObject PpOrderPage page) {
        Result<PageBean<PpOrder>> pg = super.page(page);
        return pg;
    }

    @Override
    public Result<PpOrder> detail(Long id) {
        Result<PpOrder> detail = super.detail(id);
        for (PpOrder.ItemInfo itemInfo : detail.getData().getItemInfo()) {
            itemInfo.setCover(ossStore.getUrl(itemInfo.getCover()));
        }
        return detail;
    }
}
